// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './Index'
import VueI18n from 'vue-i18n'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import axios from 'axios'
import store from '../../store/index.js'
import util from '../../libs/utils'
import { getElement } from '../../libs/utils'
import '../../libs/validate'
import router from './router/index'
import "babel-polyfill"

Vue.config.productionTip = false

Vue.prototype.jquery = function(str){
  getElement(str);
} 

//多语言
Vue.use(VueI18n);

Vue.use(util)

Vue.use(ElementUI, { zhLocale })
// Vue.use(ElementUI, {
//   i18n: (key, value) => i18n._t(key, value)
// });

const i18n = new VueI18n({
  locale: 'zh-cn',
  messages: {
    'en': require('../../locales/en.js'),
    'zh-cn': require('../../locales/cn.js'),
    ...enLocale,
    ...zhLocale
  }, 
})

Vue.prototype.AppLanguage = function (locale) {
  i18n.locale = locale;

}
Vue.prototype.getAppLanguage = function () {
  return i18n.locale;
}

Vue.prototype.http = axios;
import {
  api
} from '../../libs/api'
router.beforeEach((to, from, next) => {
  if (to.path == '/login' || to.path == '/swagger' || api.isConnected()) {
    next();
  } else {    
    next({
      path: '/login'
    });
  }
})
new Vue({
  el: '#app',
  i18n,
  router,
  store,
  template: '<App/>',
  components: {
    App
  }
})
